const { DataTypes, Sequelize } = require("sequelize");
const sequelize = require("./sequelizeBaseConfig.js");

const Resource = sequelize.define(
  "Resource",
  {
    id: {
      type: DataTypes.BIGINT,
      comment: "ID",
      autoIncrement: true, //自增
      primaryKey: true, //主键
    },
    created_at: {
      type: DataTypes.DATE,
      comment: "创建时间",
      defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"), //如果没有设置该字段的值则使用默认
    },
    updated_at: {
      type: DataTypes.DATE,
      comment: "更新时间",
      defaultValue: Sequelize.literal(
        "CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP"
      ),
    },
    url: {
      type: DataTypes.STRING(255),
      comment: "资源路径URL",
    },
    request_method: {
      type: DataTypes.STRING(10),
      comment: "请求方式",
    },
    name: {
      type: DataTypes.STRING(50),
      comment: "资源名-接口名",
    },
    parent_id: {
      type: DataTypes.INTEGER,
      comment: "父权限id",
      defaultValue: 0,
    },
    is_anonymous: {
      type: DataTypes.INTEGER,
      comment: "是否匿名访问（0-否，1-是）",
      defaultValue: 0,
    },
  },
  {
    tableName: "resource",
    timestamps: false,
  }
);

module.exports = {
  Resource,
};
